#!/usr/bin/env python2.5

##############################################################################################
#
#    LocateME! - Finds location of user in a specific building using contextual information
#    Copyright (C) <2009>  <Kattie Tay>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>
#
##############################################################################################


# Import packages
import liblocation


# Initialize global variables
fix = 0
MAP_API_KEY = "ABQIAAAAuA3xWoVLqOF0jnHFSQL8ORTP1N2wIy6k-xOQaacU0D_VGP3w4xTV7gHY3fLXeVugSTb-vUJDXQbQ_Q" 


# Initialize GPS device
def gps_init():
    global fix
    gps = liblocation.gps_device_get_new()
    gps_struct = gps.struct()
    fix = gps_struct.fix


# Get latitude value of last saved GPS data
def gps_get_latitude():
    global fix
    if fix:
        latitude = fix.latitude
    return latitude


# Get longitude value of last saved GPS data
def gps_get_longitude():
    global fix
    if fix:
        longitude = fix.longitude
    return longitude


# Get map address for Google Static Maps
def gps_get_map_addr(geocode):
    global MAP_API_KEY
    # Set map parameters
    zoom = "zoom=16"
    marker = "markers=%s,orange" %geocode
    size = "size=600x600"
    maptype = "maptype=mobile"
    key = "key=%s" %MAP_API_KEY
    sensor = "sensor=true"
    map_addr = "http://maps.google.com/staticmap?%s&%s&%s&%s&%s&%s" %(zoom, marker, size, maptype, 
                                                                      key, sensor)
    return map_addr
    
    
    